#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__author__ = 'gtlions'
import os
import sys
import cmd
import time
import cdctool
import os

class PyCDC(cmd.Cmd):
    def __init__(self):
        cmd.Cmd.__init__(self)
        current_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
        self.CDROM = '/Users/gtlions/gtlions/百度云同步盘/sync/我的文章'
        #self.CDROM = '/Users/gtlions/gtlions/01Personal/音乐'
        self.CDDIR = 'cdc/'
        self.prompt = "(PyCDC)>>:"
        self.intro = '''----------Welcome Gtlions's PyCDC----------
            '''+current_time

    def help_EOF(self):
        print "退出程序"
    def do_EOF(self, line):
        sys.exit()

    def help_walk(self):
        print "扫描光盘内容到*.cdc文件"
    def do_walk(self, filename):
        if filename == "":filename = raw_input("输入文件名称：：")
        print "扫描光盘内容保存到:'%s'" % filename
        cdctool.cdWalker(self.CDROM, filename)

    def help_dir(self):
        print "指定保存/搜索目录"
    def do_dir(self,pathname):
        if pathname == "": pathname = raw_input("输入指定保存/搜索目录：")
        self.CDDIR = pathname
        print "指定保存/搜索目录：'%s';默认是：'%s'" %(pathname,self.CDDIR)
        if os.path.exists(self.CDDIR):
            pass
        else:
            os.mkdir(self.CDDIR)


    def help_find(self):
        print "搜索关键词"
    def do_find(self, keyword):
        if keyword == "": keyword = raw_input("输入搜索关键词:")
        print "搜索关键词：'%s'" % keyword
        cdctool.cdGrep(self.CDDIR, keyword)
if __name__ == '__main__':
    cdc = PyCDC()
    cdc.cmdloop()


#cdWalker("/Users/gtlions/gtlions/01Personal/音乐","cdwalker.txt")